package com.ts.controller.achievement;

import com.ts.commom.Result;
import com.ts.constant.AchievementConstant;
import com.ts.dto.OtherResearchDTO;
import com.ts.entity.TsAchievement;
import com.ts.service.achievement.OtherResearchService;
import com.ts.service.achievement.TsAchievementService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 其他研究相关接口
 */
@RestController
@RequestMapping("/achievement/otherResearch")
@Tag(name = "其他研究相关接口", description = "其他研究的提交和查询功能")
@Slf4j
public class OtherResearchController {

    @Autowired
    private OtherResearchService otherResearchService;

    @Autowired
    private TsAchievementService tsAchievementService;

    @Operation(summary = "提交", description = "提交其他研究成果")
    @PostMapping()
    public Result saveOtherResearch(@RequestBody OtherResearchDTO otherResearchDTO) {
        log.info("otherResearchDTO:{}", otherResearchDTO);
        Long getId= otherResearchService.save(otherResearchDTO);


        String type = AchievementConstant.OTHER;
        String achievename = otherResearchDTO.getResearchName();
        String descriptipn = "7412";
        Integer level = 2;
        Integer  createdBy = 3;
        Long otherId = getId;
        tsAchievementService.addAchievement(achievename
                ,descriptipn
                ,type
                ,level
                ,createdBy
                ,otherId);
        return Result.success();
    }

    @Operation(summary = "根据ID查询", description = "根据ID查询其他研究详情")
    @GetMapping("/{id}")
    public Result<OtherResearchDTO> getById(@PathVariable Long id) {
        log.info("查询其他研究ID: {}", id);
        OtherResearchDTO researchDTO = otherResearchService.getById(id);
        return Result.success(researchDTO);
    }

    @Operation(summary = "更新", description = "更新其他研究")
    @PutMapping()
    public Result updateOtherResearch(@RequestBody OtherResearchDTO otherResearchDTO) {
        log.info("更新其他研究: {}", otherResearchDTO);
        otherResearchService.update(otherResearchDTO);
        return Result.success();
    }

    @Operation(summary = "删除", description = "根据ID删除其他研究")
    @DeleteMapping("/{id}")
    public Result deleteOtherResearch(@PathVariable Long id) {
        log.info("删除其他研究ID: {}", id);
        otherResearchService.delete(id);
        return Result.success();
    }
}
